<?php

namespace Swof\Http;

use Swoole\Http\Request as SwoRequest;

class HttpRequest extends Request
{
    /**
     * @var array
     */
    protected $server;

    /**
     * @var SwoRequest
     */
    protected $swoRequest;

    /**
     * Note:
     *
     * @param SwoRequest $swoRequest
     * @param string|null $requestMethod
     * @return \Illuminate\Contracts\Foundation\Application|mixed|\Swof\Foundation\Application
     * @throws \Exception
     * @author: Zhao Zhiqiang
     * @since: 2021/5/22 11:37
     */
    public static function initialize(SwoRequest $swoRequest, string $requestMethod = null): Request
    {
        $request = app('request');

        $request->swoRequest = $swoRequest;
        $request->server = $swoRequest->server;
        $request->method = $requestMethod ?: $swoRequest->server['request_method'];
        $request->requestUri = $swoRequest->server['request_uri'];

        return $request;
    }
}